package com.yufei.ui.utils;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yufei.utils.ExceptionUtil;



/**
 * @author jasstion
 * 2013-1-31
 * 用于表示一个类的属性的可编辑字段
 * 目前用于显示某个实体的某个属性的值以及用于通过属性的值来查询所有符合条件的实体信息
 * 
 */
public class EditTextField extends JTextField {
	private static Log mLog = LogFactory.getLog(EditTextField.class);
   private String fieldName=null;
	public String getFieldName() {
	return fieldName;
}
public void setFieldName(String fieldName) {
	this.fieldName = fieldName;
}
	public EditTextField(final Object entity,final String fieldName) {
		super();
		this.fieldName=fieldName;
		// TODO Auto-generated constructor stub
		this.addFocusListener(new FocusListener() {
			
			
			public void focusLost(FocusEvent e) {
				// TODO Auto-generated method stub
				//对里面的值重新设置到entity中
				String value=((JTextField)e.getSource()).getText();
				try {
					PropertyUtils.setProperty(entity, fieldName,value );
				}  catch (Exception e1) {
					// TODO Auto-generated catch block
					mLog.info(ExceptionUtil.getExceptionDetailsMessage(e1));
				}
			}
			
			
			public void focusGained(FocusEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	/**
	 * @param fieldName
	 * 获取该组建的value以及fieldName 然后交给查询功能模块用于查询符合条件的实体信息
	 */
	public EditTextField(String fieldName) {
		super();
		this.fieldName = fieldName;
	}

}
